const app = getApp()
import util from '../../../utils/util'
import {
  GetWorkWringCount
} from '../../../config/api'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    grider_storge:'',
    month:'2020-12',
    warn_data:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let grider_storge = wx.getStorageSync('grider')
    let month = this.getYearMonth();
    console.log(month)

    this.setData({
      grider_storge,
      month
    })

   this.getCountNum()
  },

  getYearMonth() { // 计算当前获取年月
    var myDate = new Date();
    var tYear = myDate.getFullYear();
    var tMonth = myDate.getMonth();
    var cur_day = myDate.getDate()
    var m = tMonth + 1;
    if (m.toString().length == 1) {
      m = "0" + m;
    }
    return tYear + '-' + m;
  },

  bindDateChange(e){
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      month: e.detail.value
    })
    this.getCountNum();
  },

  getCountNum(){ // 获取预警统计数
    let that =this;
    let params = {
      vollege_id:app.globalData.vollege_id,
      grider_id: that.data.grider_storge.id,
      month:that.data.month,
    }
    util.apiRequest(GetWorkWringCount,params,null).then(r => {
      console.log('r预警统计：',r)
      that.setData({
        warn_data:r.data.data
      })
    })
  },

  checkEvent(e){
    let type = e.currentTarget.dataset.type;
    let month = this.data.month;
    wx.navigateTo({
      url: '/pages/grid/events_warning/warning_list/warning_list?type='+type+'&month='+month,
    })
  }


})